package com.jg.visitor.controller.module.approver;

import com.jg.visitor.common.bean.PageDTO;
import com.jg.visitor.common.bean.ResponseBean;
import com.jg.visitor.common.bean.ServiceCode;
import com.jg.visitor.common.utils.CheckParamUtils;
import com.jg.visitor.common.utils.LoginHelper;
import com.jg.visitor.config.exception.JgException;
import com.jg.visitor.controller.dto.ApproverApproveRecordDTO;
import com.jg.visitor.controller.dto.UserDTO;
import com.jg.visitor.controller.vo.AdminRecordQueryVO;
import com.jg.visitor.controller.vo.ApproverApproveVO;
import com.jg.visitor.controller.vo.ApproverQueryVO;
import com.jg.visitor.controller.vo.EditUserVO;
import com.jg.visitor.service.ApproverService;
import com.jg.visitor.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@Api(tags = "审批人员接口")
@RequestMapping("api/approver")
@RestController
public class ApproverController {

    @Resource
    private ApproverService approverService;
    @Resource
    private UserService userService;

    @PostMapping("/select-wait-approve-record")
    @ApiOperation("分页查询审批人员待审核已审核申请记录")
    public ResponseBean selectWaitSelfApproveRecord(@RequestBody AdminRecordQueryVO approverQueryVO){
        PageDTO<ApproverApproveRecordDTO> retList = approverService.selectWaitSelfApproveRecord(approverQueryVO);

        return ResponseBean.success(retList);
    }

    @PutMapping("/operate-order")
    @ApiOperation("审批申请单")
    public ResponseBean operateOrder(@RequestBody ApproverApproveVO approverApproveVO){
        if(CheckParamUtils.isAnyParamNull(approverApproveVO.getApplyResult(),approverApproveVO.getVisitorApplyRecordId())){
            throw new JgException(ServiceCode.BAD_REQUEST);
        }

        approverService.operateOrder(approverApproveVO);

        return ResponseBean.success();
    }

    @GetMapping("/select-base-info")
    @ApiOperation("查询登录用户基本信息")
    public ResponseBean selectBaseInfo(){

        UserDTO userDTO = LoginHelper.getLoginUser();

        return ResponseBean.success(userDTO);
    }

    @PostMapping("/update-self-info")
    @ApiOperation("修改个人信息接口(管理员也可)")
    public ResponseBean updatePassword(@RequestBody EditUserVO vo){
        UserDTO userDTO = userService.updateSelfInfo(vo);

        return ResponseBean.success(userDTO);
    }
}
